function [outX outY]=plot_stat_range(combinedData,gal)
%combinedData=MF222_03022010_combinedData;
%combinedData=MF221_02182010_combinedData;
cfpIndex=3;
yfpIndex=4;
rfpIndex=5;

output_dir='C:\Users\Michael Ferry\manuscripts\MSF_dissertation_Sept2010\Figures\yGal\Accessory_files\raw_files\';

%MF221 03022010
%2-13: 0uM, 15-26 500uM, 28-39 5000uM, 41-52 wt
MF221_03022010_0=2:13;
MF221_03022010_500=15:26;
MF221_03022010_5K=28:39;
MF221_03022010_wt=41:52;

%parameters.files=(MF221_03022010_wt);
parameters.files=MF221_03022010_5K;
parameters.useGate='false';

%parameters.plot_fig=figure;
%parameters.plot_fig=figureH;
%parameters.plot_axis=plot_axis;
parameters.label=[];
parameters.dataIndex=cfpIndex;
parameters.label{1}='Log Galactose %w/v';
%parameters.label{2}='Gal3 (5000\muM Met)';
parameters.label{2}='51';
parameters.label{3}=datestr(now,30);
parameters.logBinFlag=1;
parameters.logScaleFlag=1;
parameters.cMap=[0 2];
parameters.xbins=2^7;
parameters.xBinRange=[-2 1];
parameters.ybins=2^7;
parameters.yBinRange=[1 10^5];
parameters.xplotRange=[-2 1];
parameters.yplotRange=[2 5.2];
parameters.labelFS=12;
parameters.axisFS=8;
parameters.printedXsize=7.5;
parameters.printedYsize=7;
parameters.print='true';


parameters.interpolate='false';
parameters.colorbar='false';
parameters.cbarLocation='SouthOutside';

files=parameters.files;
dataIndex=parameters.dataIndex;

plot_fig=figure;
set(plot_fig, 'PaperUnits', 'centimeters');
set(plot_fig, 'PaperSize', [parameters.printedXsize parameters.printedYsize]);
set(plot_fig, 'PaperPositionMode', 'manual');
set(plot_fig, 'PaperPosition', [0 0 parameters.printedXsize parameters.printedYsize]);
set(gca,'FontName','Times-Roman','FontSize',parameters.axisFS);

combinedDataSaved=cell(length(parameters.files),1);

%imageScale attempts to properly scale the colorbar of the image based on
%how much data each histogram contains
%imageScale=fix(log(length(combinedData{files(1)}{2}(:,dataIndex))))-1
meanVals=length(gal);

for i=1:length(files)
    if(strcmp(parameters.useGate,'true'))
        gate=combinedData{files(i)}{1}.gate.indices; 
    else
        gate=logical(combinedData{files(i)}{2}(:,dataIndex));
    end
    combinedDataSaved{i}=combinedData{files(i)}{1};

    meanVals(i,1)=mean(combinedData{files(i)}{2}(gate,dataIndex));    
end

outX=gal(files);
outY=meanVals;
%plot(gal(files),meanVals,'-o','LineWidth',2)
set(gca,'XScale','Log','XLim',[10^-5 2],'XTick',[10^-5 10^-4 10^-3 10^-2 10^-1 10^0]);
set(gca,'YScale','Log','YGrid','on');
set(gca,'YScale','Log','YLim',[10^2 10^5]);

hold on

s = fitoptions('Method','NonlinearLeastSquares',...
    'Lower',[0,0,0],...
    'Upper',[Inf,10,Inf],...
    'Startpoint',[max(meanVals),1,1]);

f = fittype('theta*(x^n)/(Kd + x^n)','coefficients',{'theta','n','Kd'},'options',s);

[parameters.c2,parameters.gof2] = fit(gal(files(2:end)),meanVals(2:end),f);
parameters.c2
parameters.gof2
fitHandle = plot(parameters.c2);
set(fitHandle(1),'Color',[1 0 0],'LineStyle','-', 'LineWidth',2,'Marker','none', 'MarkerSize',1);

p(i)=plot(gal(files),meanVals,'-o','LineWidth',2);


legend off;

xlabel('Log Galactose %w\v','FontName','Times-Roman','FontSize',parameters.labelFS);
ylabel('Log Fluorescence (A.U.)','FontName','Times-Roman','FontSize',parameters.labelFS);
%title('Gal1 Induction (wt)','FontName','Times-Roman','FontSize',parameters.labelFS);
%title('Gal1 Induction high Gal80','FontName','Times-Roman','FontSize',parameters.labelFS);
%title('Gal1 Induction inter. Gal80','FontName','Times-Roman','FontSize',parameters.labelFS);
title('Gal1 Induction low Gal80','FontName','Times-Roman','FontSize',parameters.labelFS);
%title('Gal1 Induction 5000 (\muM)','FontName','Times-Roman','FontSize',parameters.labelFS);
% powers=-5:0.5:7;
% val=10.^powers;
% Kd=0.1719;
% n=0.3689;
% amp_factor=1.508e+004;
% 
% theta=hill_func(amp_factor,n,Kd,val);

% xBinRange=[10^-5 10^1];
% xbins=length(val);
% 
% xBinRangeTotal=xBinRange(2)-xBinRange(1);
% xBinRangeDelta=xBinRangeTotal/(xbins-1);
% scaled_bins=xBinRange(1):xBinRangeDelta:xBinRange(2);

%plot(scaled_bins,theta);
%plot(val,theta);


% plot(gal(files),meanVals/max(meanVals),'-o','LineWidth',2)
% set(gca,'XScale','Log');
% set(gca,'YScale','Log');
%parameters.yBinRange=[min(fluorTotal) max(fluorTotal)];
%length(gate==1)

%line_histogram_scatter(parameters,ratioVals,fluorTotal);
%[parameters.label{3} '_outdata.mat']

set(gca,'Color','none');
set(gcf, 'Color', 'none');
if(strcmp(parameters.print,'true'))
    print(gcf, '-depsc2', [output_dir parameters.label{3}]);
    save([parameters.label{3} 'outdata.mat'], 'parameters', 'combinedDataSaved');
end
